<?php
		//ACCESO FreeHostia
	//$dbhost="mysql2.freehostia.com";
	$dbhost="198.23.57.16";
	$dbuser="davfer25_sx";
	$dbpass="s0mxarxa";
	$dbname="davfer25_sx";

     $connect=mysql_connect($dbhost,$dbuser,$dbpass) or die("Unable to Connect");
     mysql_select_db($dbname) or die("Could not open the db");

	


     /*
	 $showtablequery = "SELECT * FROM Alerta a1, Alerta_Locale a1l WHERE a1.id = a1l.id_alerta";
	 $tableAlertas_trad = "(SELECT * FROM Alerta a1, Alerta_Locale a1l WHERE a1.id = a1l.id_alerta and a1l.id_idioma = 1)"; //ORDER BY fecha_publicacion DESC LIMIT 50
	 $tableAlertas_notrad = "(SELECT * FROM Alerta a, Alerta_Locale al WHERE a.id = al.id_alerta and NOT EXISTS (SELECT * FROM Alerta a_s, Alerta_Locale al_s WHERE a.id = al.id_alerta and a.id = a_s.id and a.id = al_s.id_alerta and al_s.id_idioma = 1))"; //

     //$query_result=mysql_query($tableAlertas_notrad);
     //$query_result=mysql_query($tableAlertas_trad . " UNION " . $tableAlertas_notrad . " ORDER BY fecha_publicacion DESC LIMIT 50");
     $query_result=mysql_query($showtablequery);
     while($showtablerow = mysql_fetch_array($query_result))
     {
       print_r($showtablerow) ;
       echo "</br></br>";
     }*/
     


	 /* Solucion al problema de que no exista el idioma de la alerta 
	 	TODAS LA ALERTAS
	 */
	 //$showtablequery = "SELECT * FROM Alerta";
	 $tableAlertas_trad = "(SELECT * FROM Alerta a1, Alerta_Locale a1l WHERE a1.id = a1l.id_alerta and a1l.id_idioma = 1)"; //ORDER BY fecha_publicacion DESC LIMIT 50
	 $tableAlertas_notrad = "(SELECT * FROM Alerta a, Alerta_Locale al WHERE a.id = al.id_alerta and NOT EXISTS (SELECT * FROM Alerta a_s, Alerta_Locale al_s WHERE a.id = al.id_alerta and a.id = a_s.id and a.id = al_s.id_alerta and al_s.id_idioma = 1) GROUP BY(a.id))"; //

     //$query_result=mysql_query($tableAlertas_notrad);
     $query_result=mysql_query($tableAlertas_trad . " UNION " . $tableAlertas_notrad . " ORDER BY fecha_publicacion DESC LIMIT 50");
     while($showtablerow = mysql_fetch_array($query_result))
     {
       print_r($showtablerow) ;
       echo "</br></br>";
     }
     
     


     /* Solucion al problema de que no exista el idioma de la alerta
		ALERTAS CON FILTROS
     
	 //$showtablequery = "SELECT * FROM Alerta";
	 $tableAlertas_trad = "(SELECT * FROM Alerta a1, Alerta_Locale a1l WHERE a1.id = a1l.id_alerta and a1l.id_idioma = 1 and a1.id_categoria = 2)"; //ORDER BY fecha_publicacion DESC LIMIT 50
	 $tableAlertas_notrad = "(SELECT * FROM Alerta a, Alerta_Locale al WHERE a.id = al.id_alerta and a.id_categoria = 2 and NOT EXISTS (SELECT * FROM Alerta a_s, Alerta_Locale al_s WHERE a.id = al.id_alerta and a.id = a_s.id and a.id = al_s.id_alerta and al_s.id_idioma = 1) LIMIT 1)"; //

     //$query_result=mysql_query($tableAlertas_notrad);
     $query_result=mysql_query($tableAlertas_trad . " UNION " . $tableAlertas_notrad . " ORDER BY fecha_publicacion DESC LIMIT 50");
     while($showtablerow = mysql_fetch_array($query_result))
     {
       print_r($showtablerow) ;
       echo "</br></br>";
     }
	 */
	
	
	 
	 /* Muestra tablas base de datos
	 $showtablequery="SHOW TABLES FROM " . $dbname;
     $query_result=mysql_query($showtablequery);
     while($showtablerow = mysql_fetch_array($query_result))
     {
       echo $showtablerow[0]." </br>";
     }
	 */
?>